export const sortGroup = `update form_category set
  pos = :pos
  where object_id = :formGroup
`;
export const getGroupList = `select object_id as formGroup, object_name as groupName, pos
  from form_category
  order by pos
`;
export const createGroup = `insert into form_category
  (object_id, object_name)
  values (:formGroup, :groupName)
`;
export const renameGroup = `update form_category set
  object_name = :groupName
  where object_id = :formGroup
`;
export const removeGroup = `delete from form_category
  where object_id = :formGroup
`;

export const sortForm = `update form set
  form_group = :formGroup,
  pos = :pos
  where object_id = :schemaCode
`;
export const getFormList = `select
  object_id as schemaCode,
  object_name as schemaName,
  form_group as formGroup,
  form_property as formProperty,
  pos
  from form
  where form_group = :formGroup
  order by pos
`;
export const createForm = `insert into form
  (object_id, object_name, form_group, form_property, form_cards, pos)
  values (:schemaCode, :schemaName, :formGroup, :formProperty, :formCards, :pos)
`;
export const renameForm = `update form set
  object_name = :schemaName,
  form_property = JSON_REPLACE(form_property, '$.schemaName.defaultValue', :schemaName)
  where object_id = :schemaCode
`;
export const removeForm = `delete from form
  where object_id = :schemaCode
`;
export const saveForm = `update form set
  object_name = :schemaName,
  form_property = :formProperty,
  form_cards = :formCards,
  update_time = :updateTime
  where object_id = :schemaCode
`;
export const getFormData = `select
  object_id as schemaCode,
  object_name as schemaName,
  form_group as formGroup,
  form_property as formProperty,
  form_cards as formCards,
  flow_opened as flowOpened,
  flow_id as flowId,
  pos
  from form
  where object_id = :schemaCode
`;
export const getFormBiz = `select
  biz_object_id as bizObjectId,
  data as data,
  status as status,
  pos,
  create_by as createBy,
  date_format(create_time, '%Y-%m-%d %H:%m:%s') as createTime,
  date_format(update_time, '%Y-%m-%d %H:%m:%s') as updateTime
  from form_data
  where schema_code = :schemaCode
  order by pos, create_time desc
`;
export const createFormBiz = `insert into form_data
  (biz_object_id, schema_code, data, status)
  values (:bizObjectId, :schemaCode, :data, :status)
`;
export const saveFormBiz = `update form_data set
  data = :data,
  status = :status,
  schema_code = :schemaCode,
  update_time = :updateTime
  where biz_object_id = :bizObjectId
`;
export const removeFormBiz = `delete from form_data
  where biz_object_id in (:bizObjectIds)
`;
